<?php

    class OrderController extends Controller {
        
    	public function index() {
    		$this->_set_head_footer();
    		require_once( '../system/ecjp_m.php' );
    		$this->_load_mdao_class("t_m_order");
    		
    		$dao = new t_m_order;
    		
    		//if (isset($forms['page']) && is_numeric($forms['page'])) {
    		//	$dosearch = TRUE;
    		//	$page['current'] = $forms['page'];
    		//} else {
    		//	$page['current'] = 1;
    		//}
    		//$page['item'] = PAGE_MAX;
    		$wherearr='';
    		
    		$data = $dao->search($wherearr, $page);
    		
    		if (isset($data))
    			$this->assign('data', $data);
    		if (isset($page))
    			$this->assign('page', $page);
    		
    		
    		$this->assign('pageing', $this->fetch('page.html'));
    		
		    $this->display('order_index.html');
    		
	    }
       
        public function refer() {
        	
        
		    $this->display('order_refer.html');
		
	    }
    	
    	public function summary() {
		$this->display('order_summary.html');
	    }
	    
    	public function dl() {
		$this->display('order_dl.html');
	    }
	    
    	public function setting() {
    		require_once( '../system/ecjp_m.php' );
    		$this->_load_mdao_class("t_m_order");
    		$this->_load_php_file("Class_ERROR.php");
    		$err = new Class_ERROR();
    	
    		
    		$dao = new t_m_order;
    		$from=$this->p;
    		if ($_SERVER['REQUEST_METHOD'] == 'POST'){
				//更新消费税以外的内容
    			for($i=0;$i<=4;$i++){
    		 		$err_ems['price_'.$i]=$err->number_check($from['price_'.$i]);
    		 		$err_ems['id_'.$i]=$err->number_check($from['id_'.$i]);
    		 		$err_ems['freeset_'.$i]=$err->number_check($from['freeset_'.$i]);
    		 		$err_ems['freeprice_'.$i]=$err->number_check($from['freeprice_'.$i]);
    		 		if($err->clear){
    		 			$sql="UPDATE m_orderextraprice SET price=".$from['price_'.$i].",freeset=".$from['freeset_'.$i].",freeprice=".$from['freeprice_'.$i]." WHERE id=".$from['id_'.$i];
    		 			if($dao->exec_sql($sql)){
    		 				echo $from['content_'.$i]."更新成功！<br>";
    		 				}else{
    		 					echo $from['content_'.$i]."更新失败！<br>";
    		 				}
    		 			}
    		 	}
    			//更新消费税
				$err_ems['flag_value']=$err->number_check($from['flag_value']);
				$err_ems['flag_value_2]']=$err->number_check($from['flag_value_2]']);
    		 	$sql="UPDATE m_setflag SET flag_value=".$from['flag_value']." WHERE flag_id=1";

    		 	if($err->clear){
    		 		if($dao->exec_sql($sql)){
    		 			echo "消費税計算方法更新成功！<br>";
    		 		}else{
    		 			echo "消費税計算方法更新失败！<br>";
    		 		}
    		 		$sql="UPDATE m_setflag SET flag_value=".$from['flag_value_2']." WHERE flag_id=2";
    		 		if($dao->exec_sql($sql)){
    		 			echo "消費税率更新成功！<br>";
    		 		}else{
    		 			echo "消費税率更新失败！<br>";
    		 		}
    		 	
    		 	}
    		 	
    		 	
    		  }
    		
    		
    		
    	$sql="select * from m_orderextraprice ";
    	$data=$dao->get_rows($sql);
    		  
    	$sql="select * from m_setflag ";
    	 $data2=$dao->get_rows($sql);
    	//print_r($data);
    		
    	
 		 if (isset($data))
  			$this->assign('data', $data);
 		 if (isset($data2))
 		 	$this->assign('data2', $data2);
 		 
            $this->display('order_setting.html');
	    }
	    
    /**
     * メンバー個人の注文履歴
     * @date 2013-4-11
     * @author song
     * $page    ページ番号
     * $id		メンバーID
     * Enter description here ...
     */
    public function userGoods(){
    	require_once( '../system/ecjp_m.php' );
    	$this->_load_mdao_class("t_m_order");
    	$this->_set_head_footer();
        $g =  $this->g;
    	$dao = new t_m_order();
    	$wherearr = array();
    	$page['current'] = (isset($g['page']) && $g['page'])?$g['page']:1;
    	if (isset($g['id']) && $g['id']){
        	$id = $g['id'];
        	$wherearr[] = sprintf("( user_id = '%s')",$id);
        }
        $page['item'] = PAGE_MAX;
        $data = $dao->userGoods($wherearr,$page);//print_r(count($data));exit;
    	$this->assign('data',$data);
    	$this->assign('page', $page);
    	$this->assign('pageing', $this->fetch('page.html'));
    	$this->display('user_userGoods');
    }
    }
?>